<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <title>后台日志</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <style>
    body { font-family: Arial, sans-serif; background:#0b132b; color:#e0e0e0; }
    header { padding:16px; background:#1c2541; display:flex; justify-content:space-between; align-items:center; }
    .container { padding:12px; }
    .toolbar { margin-bottom:8px; }
    button { padding:6px 10px; border-radius:6px; border:1px solid #3a506b; background:#5bc0be; color:#0b132b; font-weight:700; cursor:pointer; }
    #log { background:#0b132b; border:1px solid #3a506b; padding:8px; border-radius:8px; height:70vh; overflow:auto; font-family: Consolas, monospace; font-size:13px; white-space:pre-wrap; }
  </style>
  <script>
    let es = null;
    let paused = false;
    function start(){
      stop();
      const cookies = document.cookie.split('; ').reduce((acc, cur)=>{ const [k,v] = cur.split('='); acc[k]=decodeURIComponent(v||''); return acc; },{});
      const pass = cookies['quant_admin_session']||'';
      const url = pass ? `/api/quant/admin/logs/stream?pass=${encodeURIComponent(pass)}` : '/api/quant/admin/logs/stream';
      es = new EventSource(url);
      es.onmessage = (e) => {
        if(paused) return;
        const logEl = document.getElementById('log');
        logEl.textContent += (e.data || '') + '\n';
        logEl.scrollTop = logEl.scrollHeight;
      };
      es.onerror = () => {};
    }
    function stop(){ if(es){ es.close(); es = null; } }
    function toggle(){ paused = !paused; document.getElementById('pauseBtn').textContent = paused ? '继续' : '暂停'; }
    function clearLog(){ document.getElementById('log').textContent = ''; }
    window.addEventListener('beforeunload', stop);
    document.addEventListener('DOMContentLoaded', start);
  </script>
</head>
<body>
  <header>
    <h2>后台日志</h2>
    <a href="/api/quant/admin/home" style="color:#5bc0be;text-decoration:none;">返回首页</a>
  </header>
  <div class="container">
    <div class="toolbar">
      <button onclick="start()">开始</button>
      <button id="pauseBtn" onclick="toggle()">暂停</button>
      <button onclick="clearLog()">清空</button>
    </div>
    <div id="log"></div>
  </div>
</body>
</html>